package com.yzr.direct;

import com.rabbitmq.client.*;
import com.yzr.util.RabbitMqClient;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class Consumer2 {

    public static void main(String[] args) throws IOException, TimeoutException {

        Connection connection = RabbitMqClient.getConnection();
        Channel channel = connection.createChannel();

        // 临时队列
        String queue = channel.queueDeclare().getQueue();

        channel.queueBind(queue,"logs","error");

        channel.basicConsume(queue,true,new DefaultConsumer(channel){
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                System.out.println("消费者2："+new String(body));
            }
        });

    }
}
